
local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.createWithData(data, node,showType)
	local sprite = nil
    if showType==2 then
        sprite=ClassRef.extend(node or cc.CSLoader:createNode(Res.MakeAttrNode))
    elseif showType==1 then
        sprite=ClassRef.extend(node or cc.CSLoader:createNode(Res.MountAttrNode))
    elseif showType==3 then
        sprite=ClassRef.extend(node or cc.CSLoader:createNode(Res.JewelAttrNode))
    else
        sprite=ClassRef.extend(node or cc.CSLoader:createNode(Res.AttrNode))
    end
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end

function ClassRef.create(node,showType)
	local sprite = nil
    if showType==2 then
        sprite=ClassRef.extend(node or cc.CSLoader:createNode(Res.MakeAttrNode))
    elseif showType==1 then
        sprite=ClassRef.extend(node or cc.CSLoader:createNode(Res.MountAttrNode))
    elseif showType==3 then
        sprite=ClassRef.extend(node or cc.CSLoader:createNode(Res.JewelAttrNode))
    else
        sprite=ClassRef.extend(node or cc.CSLoader:createNode(Res.AttrNode))
    end
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(nil)
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui.Panel:getContentSize())

	self:refresh()
end


function ClassRef:setNewScale(len)
    self:setAnchorPoint(cc.p(0.5, 0.5))
	local size = self:getContentSize()
	local scale = len / size.height
	self:setScale(scale)
end

function ClassRef:refresh()

	if self._data then
		local data = self._data

        --v.Txt, v.Title, v.colourR, v.colourG, v.colourB,v.icon

		self:setTitle(data.Title)
		self:setText(data.Txt)
        self:refreshColor()
	end
end

function ClassRef:getTitle()
	return self._data.tlt
end

function ClassRef:getText()
	return self._data.text
end

function ClassRef:setTitle(title)
    if self._ui.data_tlt then
        self._ui.data_tlt:setString(title)
    end
end

function ClassRef:setText(text)
    if self._ui.data_num then
        self._ui.data_num:setString(text)
    end
end

function ClassRef:refreshColor()
    if self._data.quality then
        if -1 == self._data.quality then
            self._ui.data_tlt:setColor( display.COLOR_GRAY )
            self._ui.data_num:setColor( display.COLOR_GRAY )
        else
            self._ui.data_tlt:setColor(Enums.QualityColor[tonumber(self._data.quality)])
            self._ui.data_num:setColor(Enums.QualityColor[tonumber(self._data.quality)])
        end
    end
end

return ClassRef
